//
//  UIButton+Extension.swift
//  KitchenAssistant
//
//  Created by 陈燕璇 on 2021/3/30.
//

import UIKit

extension UIButton {
    /// `便利`构造函数
    convenience init(imageName: String, backImageName: String) {
        self.init()
        
        setImage(UIImage(named: imageName), for: UIControl.State.normal)
        setImage(UIImage(named: imageName + "_highlighted"), for: UIControl.State.highlighted)
        setBackgroundImage(UIImage(named: backImageName), for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), for: UIControl.State.highlighted)
        
        // 会根据背景图片的大小调整尺寸
        sizeToFit()
    }
    convenience init(title: String, color:UIColor,imageName:String){
        self.init()
        setTitle(title, for: UIControl.State.normal)
        setTitleColor(UIColor.darkGray, for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: imageName), for: UIControl.State.normal)
    }
}

